<template>
    <div class="register">
        <p>注册</p>
        <div class="detail">
            <input type="text" placeholder="请输入手机号" v-model="phone" >
            <div class="yzm">
                <input type="number" placeholder="请输入验证码">
                <p class="p"><button class="button" @click.prevent="yan()">获取验证码</button></p>
            </div>
            <input type="text" placeholder="请输入密码" v-model="password">
            <input type="text" placeholder="请输入邀请码(非必填)">
        </div>
        <button type="button" class="green" @click="goLogin">确认注册</button>
    </div>
</template>
<script>
import {fapi}from'../../assets/js/farmapi.js'
export default {
    data(){
         return{
           password: null,
           phone: null,
              
         }
     },methods:{
          goLogin() {
      fapi("api/reg", { phone: this.phone, password: this.password,yqm:"" }).then(
        (res) => {
            console.log(res.data)
            if(res.data.code ==200){
                this.$router.push('/login')
            }
        }
      );
    },
    yan(){
        var btn =document.querySelector('.button')
        var time =15;
        btn.disabled=true;
         var timer = setInterval(function() {
                if (time == 0) {
                    clearInterval(timer);
                    btn.disabled = false;
                    btn.innerHTML = '获取验证码';
                    time=15
                } else {
                    btn.innerHTML = '还剩下' + time + '秒';
                    time--;
                   
                }
            }, 1000);
    }
     }

}

</script>
<style lang="less" scoped>
@import url(../../assets/css/coom.css);
.register{
    background-color: rgb(246, 246, 246);
    height: 900px;
    padding: 40px 40px;
}
p{
    font-size: 50px;
}
.p{
    font-size: 30px;
}
input,button{
    background-color: rgb(246, 246, 246);
    margin-top: 50px;
    height: 80px;
    line-height: 80px;
    width: 90%;
}
input{
    border-bottom:1px solid rgba(0,0,0,0.1);
        font-size: 30px;
}
.green{
        background-color:rgb(0, 162, 153) ;
        color:#fff;
        border-radius:40px ;
        margin-top: 80px;
    }
    .yzm{
        position: relative;
    z-index: 2;
    }
    .yzm p{
        display: inline-block;
    width: 140px;
    height: 20px;
    position: absolute;
    font-size: 16px;
    bottom:20px;
    right:100px;
    }
  .p  button{
     margin-top: 80px;
    }
    
</style>